<template>
  <div class="app-container customer-div">
    <div style="margin-top: 40px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="120px">
        <el-form-item label="采购订单号：">
          <el-input v-model="listQuery.orderSn"></el-input>
        </el-form-item>
        <el-form-item label="采购日期：">
          <el-date-picker
                  :default-time="['00:00:00']"
                  v-model="listQuery.createDate"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="供应商：">
          <el-select
            clearable
            v-model="listQuery.supplierId"
            filterable
            reserve-keyword
            placeholder="请输入关键词"
            style="width: 270px;">
            <el-option
              v-for="item in options2"
              :key="item.supplierId"
              :label="item.supplierName"
              :value="item.supplierId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="合同公司：">
          <el-input v-model="listQuery.fromCompany"></el-input>
        </el-form-item>
        <el-form-item label="业务员：" >
          <el-select v-model="listQuery.purchaseUserId" filterable placeholder="请选择" clearable>
            <el-option
                    v-for="item in userOptionList"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="流程状态：" >
          <el-select v-model="listQuery.orderState" filterable placeholder="请选择" clearable>
            <el-option
                    v-for="item in stateList"
                    :key="item.val"
                    :label="item.label"
                    :value="item.val">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="合同状态：" >
          <el-select v-model="listQuery.isClosed" filterable placeholder="请选择" clearable>
            <el-option :key="0" label="未关闭" :value="0"></el-option>
            <el-option :key="1" label="已关闭" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="交货日期：" >
            <el-date-picker
                    :default-time="['00:00:00', '23:59:59']"
                    v-model="listQuery.sendDate"
                    type="daterange"
                    format="yyyy 年 MM 月 dd 日"
                    value-format="yyyy-MM-dd"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
            </el-date-picker>
        </el-form-item>
        <el-form-item label="付款状态："  >
          <el-select v-model="listQuery.payState" filterable placeholder="请选择" multiple>
            <el-option :key="0" label="未付款" :value="0"></el-option>
            <el-option :key="1" label="部分付款" :value="1"></el-option>
            <el-option :key="2" label="已付款" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="投委订单：" >
          <el-select v-model="listQuery.isEntrust"  placeholder="请选择" clearable>
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="合同上传状态：" >
          <el-select v-model="listQuery.hasUploadContract"  placeholder="请选择" clearable>
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="入库状态："  >-->
<!--          <el-select v-model="listQuery.payState" filterable placeholder="请选择" clearable>-->
<!--            <el-option :key="0" label="已入库" :value="0"></el-option>-->
<!--            <el-option :key="1" label="部分入库" :value="1"></el-option>-->
<!--            <el-option :key="2" label="未入库" :value="2"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>
          <el-button
            v-if="purchaseAccountingExport"
            @click="downloadExcel">
            导出
          </el-button>
        </el-form-item>

      </el-form>
    </div>

      <!--数据列表-->
    <div style="font-size:14px;line-height: 30px;padding:10px 0 ">
      合同金额：<span style="font-weight: bold">{{statisticsAmount}}</span>
      <span style="padding-left:20px;">商品数量：</span><span style="font-weight: bold">{{statisticsGoodsNum}}</span>
    </div>
    <div class="table-container">
        <el-table
          :header-cell-style="{'text-align':'center'}"
          v-loading="listLoading"
          :data="tableData"
          border
          style="width: 100%; margin-top: 20px">
          <el-table-column  label="采购订单号" width="180" align="center">
            <template slot-scope="scope">
              {{scope.row.orderSn}}
              <img src="../../assets/images/zhuofei2.png" v-if="scope.row.orderState == 10" style="vertical-align: middle;"/>
              <img src="../../assets/images/bian.png" v-if="scope.row.isChange==1" style="vertical-align: middle;"/>
              <span v-if="scope.row.isEntrust == 1" style="display: inline-block;width:22px;line-height: 18px;background: green;color:#fff;font-size:12px;border-radius: 4px">投</span>
            </template>
          </el-table-column>

          <el-table-column
                  label="供应商名称"
                  width="200">
            <template slot-scope="scope">
              {{scope.row.supplierName}}
            </template>
          </el-table-column>
          <el-table-column
                  label="合同公司"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.fromCompany}}
            </template>
          </el-table-column>
          <el-table-column
                  label="业务员"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.userName}}
            </template>
          </el-table-column>
          <el-table-column
                  label="合同数量"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.goodsAllNum}}
            </template>
          </el-table-column>
          <el-table-column
                  label="合同金额"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.orderAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  label="已付款金额"
                  width="100"
                  align="center">
            <template slot-scope="scope">
                 {{scope.row.hasPaidAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  label="未付款金额"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.unPaidAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  label="申请中金额"
                  width="100"
                  align="center">
            <template slot-scope="scope">
              {{scope.row.applyAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="付款状态"
                  width="150">
            <template slot-scope="scope">
              {{scope.row.payState | fiferPayState}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="已入库数量"
                  width="100">
            <template slot-scope="scope">
              {{scope.row.goodsInNum}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="未入库数量"
                  width="100">
            <template slot-scope="scope">
              {{scope.row.goodsUnInNum}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="已入库金额 "
                  width="100">
            <template slot-scope="scope">
                  {{scope.row.goodsInAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="未入库金额 "
                  width="100">
            <template slot-scope="scope">
                {{scope.row.goodsUnInAmount}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="结算方式"
                  width="150">
            <template slot-scope="scope">
              {{scope.row.remark}}
            </template>
          </el-table-column>

          <el-table-column
                  align="center"
                  label="付款时间"
                  width="150">
            <template slot-scope="scope">
              {{scope.row.payTime}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="合同状态"
                  width="150">
            <template slot-scope="scope">
                  {{scope.row.isClosed ==1 ? '已关闭' : '未关闭'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  label="流程状态"
                  width="100">
            <template slot-scope="scope">
              {{scope.row.orderState | fifterState}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="合同文件"
            width="100">
            <template slot-scope="scope">
                <i class="el-icon-picture-outline" v-if="scope.row.contractUrl != ''"  style="cursor: pointer;font-size: 24px" @click="urlOpen(scope.row.contractUrl)"></i>
            </template>
          </el-table-column>
          <el-table-column
                  fixed="right"
                  align="center"
                  label="操作"
                  width="100">
            <template slot-scope="scope">
                <el-button type="text" @click="toPurchaseList(scope.row)">付款记录</el-button>
                 <!----已付金额-入库金额大于0时  显示退款操作 ---->
                <el-button type="text" @click="seeRefundForm(scope.row)" v-if="scope.row.hasPaidAmount - scope.row.goodsInAmount> 0 ">退款</el-button>
            </template>
          </el-table-column>

        </el-table>
      </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>

      <!--申请支付-->
      <el-dialog
              :close-on-click-modal="false"
              :beforeClose="handleClose3"
              title="申请付款"
              :visible.sync="dialogVisible3"
              width="400px">
          <el-form :model="appleForm" size="mini" label-width="140px"  ref="appleForm" :rules="rules3">
               <el-form-item label="供应商：" >{{appleForm.supplierName}}</el-form-item>
               <el-form-item label="合同公司：" >{{appleForm.fromCompany}}</el-form-item>
              <el-form-item label="合同金额：" >{{appleForm.orderAmount}}</el-form-item>
              <el-form-item label="已支付金额：" >{{appleForm.hasPaidAmount}}</el-form-item>
              <el-form-item label="未付款金额：">{{appleForm.unPaidAmount}}</el-form-item>
              <el-form-item label="可申请金额：">{{appleForm.canApplyAmount}}</el-form-item>
              <el-form-item label="付款方式：" prop="applyPaymentCode">
                <el-select v-model="appleForm.applyPaymentCode" class="input-width" style="width:195px" placeholder="请选择">
                  <el-option value="cash" label="现汇" key="cash" ></el-option>
                  <el-option value="chengdui" label="承兑" key="chengdui" ></el-option>
                  <el-option value="cashBalance" :label="'现金余额'+'('+appleForm.CashBalance+')'" key="cashBalance" ></el-option>
                  <el-option value="chengduiBalance" :label="'承兑余额'+'('+appleForm.ChengduiBalance+')'" key="chengduiBalance" ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="申请付款金额：" prop="applyPayAmount">
              <el-input v-model="appleForm.applyPayAmount"></el-input>
            </el-form-item>
              <el-form-item label="付款时间：" prop="applyPayTime">
                  <el-date-picker
                          v-model="appleForm.applyPayTime"
                          value-format="yyyy-MM-dd HH:mm"
                          type="datetime"
                          placeholder="选择日期时间">
                  </el-date-picker>
              </el-form-item>
              <el-form-item label="付款备注：">
                  <el-input v-model="appleForm.applyPayRemark" type="textarea" :autosize="{ minRows: 2, maxRows: 6}"></el-input>
              </el-form-item>
          </el-form>
         <div style="color:red;padding:0 16px;font-size:12px">注：选择承兑支付时，请确认已有承兑票据</div>
          <span slot="footer" class="dialog-footer">
              <el-button @click="handleClose3">取 消</el-button>
              <el-button type="primary" @click="handleConfirm3" :loading="btnLoading3">确 定</el-button>
          </span>
      </el-dialog>

    <!--退款弹窗-->
    <el-dialog
            :close-on-click-modal="false"
            :beforeClose="handleClose5"
            title="退款"
            :visible.sync="dialogVisible5"
            width="500px">
      <el-form :model="refundForm" size="mini" label-width="100px" ref="refundForm" :rules="rules5">
        <el-form-item label="供应商：" >
          {{refundForm.supplierName}}
        </el-form-item>
        <el-form-item label="合同公司：" >
          {{refundForm.fromCompany}}
        </el-form-item>
        <el-form-item label="合同金额：" >
          {{refundForm.orderAmount }}
        </el-form-item>
        <el-form-item label="已付款：" >
          {{refundForm.hasPaidAmount }}
        </el-form-item>
        <el-form-item label="入库金额：" >
          {{refundForm.goodsInAmount}}
        </el-form-item>
        <el-form-item label="可退款金额：" >
          {{refundForm.canRefundAmount}}
        </el-form-item>
        <el-form-item label="退款方式：" prop="refundPaymentCode">
          <el-radio-group v-model="refundForm.refundPaymentCode">
            <el-radio label="chengdui">承兑</el-radio>
            <el-radio label="cash">现金</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="退款金额：" prop="refundAmount">
          <el-input  v-model="refundForm.refundAmount" style="width:150px"></el-input>
        </el-form-item>
        <el-form-item label="退款去向：" prop="refundTo">
          <el-radio-group v-model="refundForm.refundTo">
            <el-radio label="account_pay">帐户</el-radio>
            <el-radio label="advance_pay">预付款</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注信息：">
          <el-input type="textarea" v-model="refundForm.refundRemark" :autosize="{ minRows: 2, maxRows: 6}"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose5">取 消</el-button>
          <el-button type="primary" @click="handleConfirm5" :loading="btnLoading5">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
  import {getCustomerOption,getOrderUsersList,purchaseOrderList,supplierList,purchaseAddApplyPay,supplierBalanceInfo,orderRefund} from '@/api/partner'
  import {goodsList} from '@/api/company'
  import {formatDate} from '@/utils/date';
  import store from '@/store'
  import { mapGetters } from 'vuex'
  import {validateCommission} from '@/utils/validate';
  const defaultListQuery={
    pageNum: 1,
    pageSize: 10,
    supplierId: '',
    orderSn:'',
    goodsKingId:'',
    purchaseUserId:'',
    fromCompany:'',
    createDate:null,
    sendDate:null,
    tab:'all',
    orderState:null,
    payState:[],
    isClosed:null,
    isEntrust:'',
    hasUploadContract:''
  };
  const defaultAppleForm={
    "orderId"     : '',    //采购单ID
    "applyPaymentCode" : "",  //支付方式
    "applyPayTime"   : "",    //支付时间
    "applyPayAmount" : '',  //支付金额
    "applyPayRemark" : "" , //备注
    orderAmount:'',
    unPaidAmount:'',
    hasPaidAmount:'',
    canApplyAmount:'',
    contractUrl:'',
    fromCompany:'',
    supplierName:'',
    CashBalance:'',
    ChengduiBalance:''
  };

  const defaultRefundForm = {
    orderId :'',
    supplierName:'',
    fromCompany:'',
    orderAmount:'',
    hasPaidAmount:'',
    goodsInAmount:'',
    canRefundAmount:'',
    refundAmount:'',
    refundPaymentCode:'',
    refundTo:'',
    refundRemark:'',
  };
  export default {
    name: "index",
    data(){
      const isvalidateApplyPayAmount = (rule, value, callback) => {
        if (!validateCommission(parseFloat(value))) {
          callback(new Error('非负整数或小数'))
        }else if(this.appleForm.applyPaymentCode == 'cash' && value > this.appleForm.canApplyAmount){
          callback(new Error('超过可申请金额'))
        }else if(this.appleForm.applyPaymentCode == 'chengdui' &&  this.appleForm.canApplyAmount <= 0){
          callback(new Error('可申请金额小于等于0，不可以再次申请'))
        }else if(this.appleForm.applyPaymentCode == 'cashBalance' && value > this.appleForm.canApplyAmount){
          callback(new Error('超过可申请金额'))
        }else if(this.appleForm.applyPaymentCode == 'cashBalance' && value > this.appleForm.CashBalance){
          callback(new Error('超过现金余额'))
        }else if(this.appleForm.applyPaymentCode == 'chengduiBalance' && value > this.appleForm.canApplyAmount){
          callback(new Error('超过可申请金额'))
        }else if(this.appleForm.applyPaymentCode == 'chengduiBalance' && value > this.appleForm.ChengduiBalance){
          callback(new Error('超过承兑余额'))
        }else {
          callback()
        }
      };
      const isvalidateRefundAmount = (rule, value, callback) => {
        if (!validateCommission(parseFloat(value))) {
          callback(new Error('非负整数或小数'))
        }else if(parseFloat(value) > this.refundForm.canRefundAmount){
          callback(new Error('超过可退款金额'))
        }else {
          callback()
        }
      };

      return {
        listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
        tableData: [],
        count: 0,
        listLoading: false,
        userOptionList:[],
        roles:store.getters.roles ? store.getters.roles : [],
        loading:false,
        options:[],
        loading2:false,
        options2:[],
        stateList:[
          {label:'待采购员审核',val:0},
          {label:'作废',val:10},
          {label:'待产品负责人审核',val:20},
          {label:'待采购部门负责人确认',val:23},
          {label:'待总经理审核',val:25},
          {label:'流程结束',val:40},
          {label:'交易关闭',val:50},
        ],
        statisticsAmount:'',
        statisticsGoodsNum:'',
        dialogVisible3:false,
        rules3:{
          applyPaymentCode:[{required: true, trigger: 'change' ,message: '请选择支付方式',}],
          applyPayTime:[{required: true, trigger: 'change' ,message: '请选择支付时间',}],
          applyPayAmount:[{required: true, trigger: 'blur' ,validator:isvalidateApplyPayAmount,}],
          },
       appleForm:JSON.parse(JSON.stringify(defaultAppleForm)),
       btnLoading3:false,


        dialogVisible5:false,
        btnLoading5:false,
        refundForm:JSON.parse(JSON.stringify(defaultRefundForm)),
        rules5:{
          refundAmount:[{required: true, trigger: 'blur' ,validator:isvalidateRefundAmount,}],
          refundPaymentCode:[{required: true, trigger: 'change' ,message: '请选择退款方式',}],
          refundTo:[{required: true, trigger: 'change' ,message: '请选择退款去向',}],
        },
      }
    },
    computed: {
      ...mapGetters([
        'name',
        'mobile',
        'userId',
        'isMange',
      ]),
      purchaseAccountingExport(){
        if(this.roles.indexOf("purchaseAccountingExport") != -1){
          return true
        }else{
          return false
        }
      },
    },
    created() {
      let now = new Date();
      let nowMonth = now.getMonth(); //当前月
      let nowYear = now.getFullYear(); //当前年
      //本月的开始时间
      let monthStartDate = new Date(nowYear, nowMonth, 1);
      //本月的结束时间
      let monthEndDate = new Date(nowYear, nowMonth+1, 0,23,59,59);
      let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
      let endDate = formatDate(monthEndDate, 'yyyy-MM-dd');
      this.listQuery.createDate = [startDate,endDate];
      this.getList();
      this.getUserOptionList();
      this.getSupplierList()
    },
    filters: {
      formatCreateTime(time) {
        if(time){
          let date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
        }else{
          return '--'
        }
      },
      fiferPayState(val){
        if(val == 0){
          return '未付款'
        }else if(val == 1){
          return '部分付款'
        }else if(val == 2){
          return '已付款'
        }
      },
      fifterState(val){
        if(val == 0){
          return '待采购员审核'
        }else if(val == 10){
          return '作废'
        }else if(val == 20){
          return '待产品负责人审核'
        }else if(val == 23){
          return '待采购部门负责人确认'
        }else if(val == 25){
          return '待总经理审核'
        }else if(val == 30){
          return '待财务负责人审核'
        }else if(val == 40){
          return '流程结束'
        }else if(val == 50){
          return '交易关闭'
        }
      },
    },
    methods:{
      urlOpen(url){
        window.open(url)
      },
      //显示退款
      seeRefundForm(item){
        this.dialogVisible5 = true;
        this.refundForm.orderId = item.orderId;
        this.refundForm.supplierName = item.supplierName;
        this.refundForm.fromCompany = item.fromCompany;
        this.refundForm.orderAmount = item.orderAmount;
        this.refundForm.hasPaidAmount = item.hasPaidAmount;
        this.refundForm.goodsInAmount = item.goodsInAmount;
        this.refundForm.canRefundAmount = item.hasPaidAmount - item.goodsInAmount;
        this.refundForm.refundAmount = '';
        this.refundForm.refundPaymentCode = '';
        this.refundForm.refundTo = '';
        this.refundForm.refundRemark = '';
      },
      //关闭退款弹窗
      handleClose5(){
        this.dialogVisible5 = false;
        this.$refs.refundForm.clearValidate();
      },

      //提交退款款弹窗
      handleConfirm5(){
        this.$refs.refundForm.validate((valid) => {
          if (valid) {
            this.btnLoading5 = true;
            let data = JSON.parse(JSON.stringify(this.refundForm));
            orderRefund(data).then(()=>{
              this.btnLoading5 = false;
              this.handleClose5();
              this.getList();
            }).catch(()=>{
              this.btnLoading5 = false;
            })
          }
        })
      },


      //下载excle
      downloadExcel(){
        let data = JSON.parse(JSON.stringify(this.listQuery));
        data.isExport = 1;
        purchaseOrderList(data).then(res => {
          require.ensure([], () => {
            const { export_json_to_excel } = require('sheet/Export2Excel');
            const tHeader = res.title;
            const filterVal = res.columns;
            const list = res.list;
            const data = this.formatJson(filterVal, list);
            export_json_to_excel(tHeader, data, res.fileName);
          })
        })
      },

      //下载表格数据格式化
      formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
      },
        //显示申请付款弹窗
        showDialog3(item){
          this.dialogVisible3 = true;
          supplierBalanceInfo({supplierId:item.supplierId}).then((res)=>{
            if(item.fromCompany.indexOf('普利成') != -1){
                this.appleForm.CashBalance = res.polisenCashBalance;
                this.appleForm.ChengduiBalance = res.polisenChengduiBalance;
            }else if(item.fromCompany.indexOf('塑盟') != -1){
              this.appleForm.CashBalance = res.sumengCashBalance;
              this.appleForm.ChengduiBalance = res.sumengChengduiBalance;
            }else if(item.fromCompany.indexOf('泛塑') != -1){
              this.appleForm.CashBalance = res.fansuCashBalance;
              this.appleForm.ChengduiBalance = res.fansuChengduiBalance;
            }
          });
          this.appleForm.orderId = item.orderId;
          this.appleForm.applyPaymentCode = '';
          this.appleForm.applyPayTime = '';
          this.appleForm.applyPayAmount = '';
          this.appleForm.applyPayRemark = '';
          this.appleForm.orderAmount = item.orderAmount;
          this.appleForm.unPaidAmount = item.unPaidAmount;
          this.appleForm.hasPaidAmount = item.hasPaidAmount;
          this.appleForm.canApplyAmount = item.canApplyAmount;
          this.appleForm.contractUrl = item.contractUrl;
          this.appleForm.fromCompany = item.fromCompany;
          this.appleForm.supplierName = item.supplierName;

        },
        //关闭申请付款弹窗
        handleClose3(){
            this.dialogVisible3 = false;
            this.$refs.appleForm.clearValidate();
        },
        //提交申请付款
        handleConfirm3(){
            this.$refs['appleForm'].validate((valid) => {
                if (valid) {
                  if(this.appleForm.applyPaymentCode == 'chengdui' &&  this.appleForm.canApplyAmount <= 0){
                    this.$message({
                      message: '承兑支付时可申请金额小于等于0，不可以再次申请',
                      type: 'error'
                    });
                    return false
                  }else if(this.appleForm.contractUrl == ''){
                    this.$message({
                      message: '上传合同后，才能申请支付',
                      type: 'error'
                    });
                    return false
                  }
                    this.btnLoading3 = true;
                    let data = {};
                    data.orderId = this.appleForm.orderId;
                    data.applyPaymentCode = this.appleForm.applyPaymentCode;
                    data.applyPayTime = this.appleForm.applyPayTime;
                    data.applyPayAmount = this.appleForm.applyPayAmount;
                    data.applyPayRemark = this.appleForm.applyPayRemark;
                    purchaseAddApplyPay(data).then(()=>{
                          this.btnLoading3 = false;
                          this.dialogVisible3 = false;
                          this.getList()
                      }).catch(()=>{
                          this.btnLoading3 = false;
                      })
                }
            })
        },

      //去采购合同付款列表
      toPurchaseList(item){
        let routeData = this.$router.resolve({name:'purchaseList',query:{orderSn:item.orderSn}});
        window.open(routeData.href);
      },
      //商品
      remoteMethod(query) {
        if (query !== '') {
          this.loading = true;
          this.loading = false;
          goodsList({keywords:query}).then((res)=>{
            this.options = res.list;
          })
        } else {
          this.options = [];
        }
      },

      //供应商
      getSupplierList() {
          supplierList().then((res)=>{
            this.options2 = res;
          })
      },

      //获取员工下拉选项
      getUserOptionList(){
        getOrderUsersList().then((res)=>{
          this.userOptionList = res;
        })
      },

      //选择员工名称
      handleSelectUserName(key,item){
        this.listQuery[key] = item.userId;
      },

      //客户名称输入匹配
      querySearch(queryString, cb){
        getCustomerOption({keywords:queryString}).then((res)=>{
          cb(res);
        })
      },

      //选择客户名称
      handleSelectCustomerName(item){
        this.listQuery.keywords = item.customerName
      },

      /**
       * 切换选择状态
       */
      handleSelect(key, keyPath){
        this.listQuery.tab = key;
        if(key != 'my' && key != 'all'){
          this.listQuery.orderState = null;
        }
        this.handleSearchList();
      },
      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },

      handleSearchList(){
        this.listQuery.pageNum = 1;
        this.getList();
      },

      //获取订单列表
      getList() {
        this.listLoading = true;
        purchaseOrderList(this.listQuery).then(response => {
          this.tableData = response.list;
          this.count = response.count;
          this.statisticsAmount = response.statisticsAmount;
          this.statisticsGoodsNum = response.statisticsGoodsNum;
          this.listLoading = false;
        }).catch(()=>{
          this.listLoading = false;
        });
      },

    },
  }
</script>

<style scoped lang="scss">

</style>
